class MessageUtil {
	public constructor() {
	}

	private static _messagePool:TipsItem[] = [];
	private static _poolMax:number = 10;
	private static _poolIndex:number = 0;

	/**
	 * 消息tips
	 */
	public static message(str:string){
		MessageUtil.createMessageTips(str);
	}

	/**
	 * 提示
	 */
	public static tips(str:string){
		MessageUtil.message(str);
	}

	/**
	 * 报错
	 */
	public static error(str:string){
		MessageUtil.message(str);
	}

	/**
	 * 带有道具icon的tips
	 */
	// public static IconTips(str:string, prop_id:number){
	// 	MessageUtil.createMessageTips(str, prop_id);
	// }

	/**
	 * 是否为配置字符串
	 */
	public static isConfig(str:string){
		return false;
	}
	
	/**
	 * 生成MessageTips
	 */
	private static createMessageTips(str:string){
		let tips:TipsItem = null;
		let pool = MessageUtil._messagePool;
		let max = MessageUtil._poolMax;
		let data = {
			str : str,
		}

		if(pool.length < max){
			tips = new TipsItem(data);
			tips.cacheAsBitmap = true;
			
			pool.push(tips);
		}else{
			if(MessageUtil._poolIndex < pool.length){
				tips = pool[MessageUtil._poolIndex];
				tips.changeData(data);
				tips.visible = true;
				MessageUtil._poolIndex++;
			}else{
				MessageUtil._poolIndex = 0;
			}
		}

		if(tips){
			GlobalManager.instance().addChildToLayer(tips, LayerType.Tips);
			tips.x = tips.parent.width - tips.width >> 1;
			tips.y = tips.parent.height - tips.height >> 1;

			tips.startAction();
		}
	}

	/**
	 * 释放缓存
	 */
	public static release(){
		for(let v of MessageUtil._messagePool)
		{
			v.destory();
		}
		MessageUtil._messagePool = [];
		MessageUtil._poolIndex = 0;
	}
}